package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.business.domain.Department;
import cn.wolfcode.car.business.domain.Employee;
import cn.wolfcode.car.business.query.EmployeeQuery;
import cn.wolfcode.car.business.service.IEmployeeService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.xpath.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/business/employee")
public class EmployeeController {

    private String prefix="/business/employee";

    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/listPage")
    public String listPage(){
        return prefix+"/list";
    }
    //分页+过滤
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<Employee> query(EmployeeQuery qo){
        return employeeService.query(qo);
    }
    @RequestMapping("/addPage")
    public String toadd(){
        return prefix+"/add";
    }
    @RequestMapping("/editPage")
    public String toedit(Long id,Model model){
        Employee employee = employeeService.selectByPrimaryKey(id);
        model.addAttribute("employee",employee);
        return prefix+"/edit";
    }
    //添加
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(Employee employee){
         employeeService.insert(employee);
         return new AjaxResult().success("添加成功！");
    }
    //编辑
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(Employee employee){
        employeeService.updateByPrimaryKey(employee);
        return new AjaxResult().success("编辑成功！");
    }
    //删除
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult edit(String ids){
        employeeService.deleteByPrimaryKey(Long.valueOf(ids));
        return new AjaxResult().success("删除成功！");
    }
    //去部门详情页面
    @RequestMapping("/todeptDetail")
    public String todeptDetail(Long id,Model model){
        Department department=employeeService.selectDept(id);
        model.addAttribute("department",department);
        return prefix+"/deptDetail";
    }

}
